<template>
  <div class="login">
    <div class="inner-box">
      <div class="top"></div>

      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="0"
        class="demo-ruleForm"
        size="small"
      >
        <!-- 输入账号 -->
        <el-form-item prop="account">
          <el-input
            type="text"
            v-model="ruleForm.account"
            autocomplete="off"
            prefix-icon="iconfont icon-account"
          ></el-input>
        </el-form-item>
        <!-- 输入密码 -->
        <el-form-item prop="password">
          <el-input
            :type="visiable ? 'text' : 'password'"
            v-model="ruleForm.password"
            autocomplete="off"
            prefix-icon="iconfont icon-password"
          >
            <!-- 图标插槽 -->
            <i
              slot="suffix"
              class="iconfont"
              :class="visiable ? 'icon-eye-open' : 'icon-eye-close'"
              @click="visiable = !visiable"
            ></i>
          </el-input>
        </el-form-item>

        <!-- 用户组 -->
        <!-- <el-form-item label="">
    <el-select v-model="formInline.region" placeholder="请选择用户组">
      <el-option label="普通VIP" value="普通VIP"></el-option>
      <el-option label="高级VIP" value="高级VIP"></el-option>
    </el-select>
    </el-form-item> -->

        <el-form-item>
          <el-button type="primary" class="login-btn" @click="submitLogin"
            >登陆</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { Login } from "@/api/user.js";

export default {
  components: {},
  data() {
    return {
      ruleForm: {
        account: "",
        password: "",
        // region: '',
      },
      formInline: {},
      // 控制眼睛属性.
      visiable: false,
      rules: {
        account: [
          { required: true, message: "请输入账号", trigger: "blur" },
          { min: 2, max: 12, message: "账号格式错误", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, max: 12, message: "密码格式错误", trigger: "blur" },
        ],
        // region: [
        //   { required: true, message: '请选择活动区域', trigger: 'change' }
        // ],
      },
    };
  },
  methods: {
    submitLogin() {
      this.$refs["ruleForm"].validate(async (valid) => {
        if (valid) {
          let res=await Login(this.ruleForm);
          console.log(res.data);
          let {code,msg}=res.data
          if(code==0){
            localStorage.setItem('t_k',res.data.token)
            localStorage.setItem('role',res.data.role)
            // this.$message.success(msg);
            this.$router.push('/home')
          }else{
             this.$message.error(msg);
          }
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.login {
  width: 100%;
  height: 100%;
  background-color: #2d3a4b;
  display: flex;
  justify-content: center;
  align-items: center;
  .inner-box {
    width: 320px;
    height: 400px;
    .top {
      height: 100px;
      background-color: pink;
    }
    /deep/.el-input__inner {
      background-color: transparent;
    }
    .login-btn {
      width: 100%;
    }
  }
}
</style>

